import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.Scanner;

import javax.swing.JOptionPane;

import Controllers.GlobalData;
import Controllers.RequestManager;
import Entity.Request;
import Entity.User;
import Entity.Worker;
import Exception.ICMException;
import ICM_OCSF.Client;


public class CloseRequest 
{
	int inspedtorId;
	int requestId;
	private static String LocalNetworkConfigurtaion = "ConfigServerOption.txt";
	public Request request;
	public Client client;
	 
	public CloseRequest()
	{
		
	}
	 
	//Connect to the Server.
	public void enterToSystem()
	{
		String ip=null;
		String port=null;
		Scanner in;
		try 
		{
			in = new Scanner(new FileReader(LocalNetworkConfigurtaion));
			in.useDelimiter(",");
			while (in.hasNext())
			{
				ip = in.next();
				port =  in.next();
			}
			int iport = Integer.parseInt(port);
			client = new Client(ip,iport);
			try {
				client.openConnection();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} 
		catch (FileNotFoundException e) 
		{
			JOptionPane.showMessageDialog(null,"Connection Failure", "Error",JOptionPane.ERROR_MESSAGE);
			e.printStackTrace();	
		}
	}
	public void requestNumber(int number)
	{
		this.requestId = number;
	}
	
	public void inspectorId(int number)
	{
		this.inspedtorId = number;
	}
	public boolean closeRequest()
	{
		List<Request> requestToChoose = RequestManager.getInstance().getAllRequestToCloseRequest(inspedtorId);
		for(Request req : requestToChoose)
		{
			if(req.getRequestId() == requestId)
				return request.close();
		}
		return false;
	}
}
